home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / c-tools / c_examples / msgprompt / gadget.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-02  |  3.6 KB  |  161 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // gadget.cpp
  3. //
  4. // Jeffry A Worth
  5. // Nov 9, 1995
  6. //////////////////////////////////////////////////////////////////////////////
  7.  
  8. //////////////////////////////////////////////////////////////////////////////
  9. // INCLUDES 
  10. #include "aframe:include/rastport.hpp"
  11. #include "aframe:include/gadget.hpp"
  12.  
  13. //////////////////////////////////////////////////////////////////////////////
  14. //
  15.  
  16. AFGadget::AFGadget()
  17.     :m_newregion(NULL),
  18.     m_oldregion(NULL),
  19.     m_pgadget(NULL),
  20.     m_flags(NULL)
  21. {
  22. }
  23.  
  24. AFGadget::~AFGadget()
  25. {
  26.     // Call DestroyObject if not already called
  27.     if(m_pgadget)
  28.         DestroyObject();
  29. }
  30.  
  31. void AFGadget::DestroyObject()
  32. {
  33.   if(m_pgadget && (!(m_flags & AFGADGET_OWNERSTRUCT)) ) {
  34.     RemoveGadget();
  35.     delete m_pgadget;
  36.     m_pgadget = NULL;
  37.     m_flags = NULL;
  38.   }
  39. }
  40.  
  41. void AFGadget::Create(AFWindow* pwindow, AFRect *rect, ULONG id)
  42. {
  43.     m_pwindow = pwindow;
  44.     m_pgadget = new struct ExtGadget;
  45.     m_pgadget->NextGadget = NULL;
  46.     m_pgadget->LeftEdge = m_pgadget->BoundsLeftEdge = rect->TopLeft()->m_x;
  47.     m_pgadget->TopEdge = m_pgadget->BoundsTopEdge = rect->TopLeft()->m_y;
  48.     m_pgadget->Width = m_pgadget->BoundsWidth = rect->Width();
  49.     m_pgadget->Height = m_pgadget->BoundsHeight = rect->Height();
  50.     m_pgadget->GadgetID = id;
  51.     FillGadgetStruct(m_pgadget);
  52.     m_pgadget->Flags|=GFLG_EXTENDED;
  53.     m_pgadget->UserData = this;
  54.  
  55.     // Gadget Tracking - Not implemented yet!
  56.     //m_pwindow->m_pgadgets = new AFNode(m_pgadget,m_pwindow->m_pgadgets);
  57.  
  58.     AddGadget();
  59. }
  60.  
  61. void AFGadget::Create(AFWindow* pwindow, LPExtGadget psgadget)
  62. {
  63.     // Set up OWNERSTRUCT Gadget
  64.     m_pgadget = psgadget;
  65.     m_pwindow = pwindow;
  66.     m_flags |= AFGADGET_OWNERSTRUCT;
  67.     psgadget->UserData = this;
  68.  
  69.     // Gadget Tracking - Not implemented yet!
  70.     // m_pwindow->m_pgadgets = new CNode(m_pgadget,m_pwindow->m_pgadgets);
  71.  
  72.     AddGadget();
  73. }
  74.  
  75. void AFGadget::FillGadgetStruct(LPExtGadget psgadget)
  76. {
  77.   psgadget->Flags = GFLG_GADGHCOMP|GFLG_EXTENDED;
  78.   psgadget->Activation = GACT_RELVERIFY | GACT_IMMEDIATE | GACT_FOLLOWMOUSE;
  79.   psgadget->GadgetType = GTYP_BOOLGADGET;
  80.   psgadget->GadgetRender = NULL;
  81.   psgadget->SelectRender = NULL;
  82.   psgadget->GadgetText = NULL;
  83.   psgadget->MutualExclude = NULL;
  84.   psgadget->SpecialInfo = NULL;
  85.   psgadget->MoreFlags = GMORE_GADGETHELP|GMORE_BOUNDS;
  86.   return;
  87. }
  88.  
  89. void AFGadget::AddGadget()
  90. {
  91.   ::AddGadget(m_pwindow->m_pWindow,(LPGadget)m_pgadget,-1);
  92. }
  93.  
  94. void AFGadget::RemoveGadget()
  95. {
  96.   ::RemoveGadget(m_pwindow->m_pWindow,(LPGadget)m_pgadget);
  97. }
  98.  
  99. BOOL AFGadget::BeginPaint()
  100. {
  101.     Rectangle rect;
  102.     AFRect drect;
  103.  
  104.     if(m_newregion)
  105.         return FALSE;
  106.  
  107.     GetDisplayRect(&drect);
  108.     rect.MinX = drect.TopLeft()->m_x;
  109.     rect.MinY = drect.TopLeft()->m_y;
  110.     rect.MaxX = drect.BottomRight()->m_x;
  111.     rect.MaxY = drect.BottomRight()->m_y;
  112.  
  113.     if(m_newregion=NewRegion()) {
  114.         if(!OrRectRegion(m_newregion,&rect)) {
  115.             DisposeRegion(m_newregion);
  116.             m_newregion=NULL;
  117.             return FALSE;
  118.         }
  119.         m_oldregion=InstallClipRegion(m_pwindow->m_pWindow->WLayer,m_newregion);
  120.         return TRUE;
  121.     }
  122.     return FALSE;
  123. }
  124.  
  125. void AFGadget::EndPaint()
  126. {
  127.     if(m_newregion) {
  128.         InstallClipRegion(m_pwindow->m_pWindow->WLayer,m_oldregion);
  129.         DisposeRegion(m_newregion);
  130.         m_newregion=NULL;
  131.     }
  132. }
  133.  
  134. void AFGadget::GetDisplayRect(AFRect* rect)
  135. {
  136.     rect->SetRect(m_pgadget->LeftEdge,m_pgadget->TopEdge,
  137.             m_pgadget->LeftEdge+m_pgadget->Width-1,m_pgadget->TopEdge+m_pgadget->Height-1);
  138. }
  139.  
  140. void
  141. AFGadget::EraseGadget()
  142. {
  143.     AFRastPort rp(m_pwindow);
  144.     AFRect rect;
  145.  
  146.     GetDisplayRect(&rect);
  147.     rp.SetAPen(0);
  148.     rp.RectFill(&rect);
  149. }
  150.  
  151. void
  152. AFGadget::DrawGadget()
  153. {
  154.     ::RefreshGadgets((LPGadget)m_pgadget,m_pwindow->m_pWindow,NULL);
  155. }
  156.  
  157. ULONG AFGadget::GadgetID()
  158. {
  159.     return m_pgadget->GadgetID;
  160. }
  161.